﻿using Microsoft.Reporting.WinForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QuanLyPhongGiam
{
    public partial class frmReporttQuaHanTamGiam : Form
    {
        int pageIndex = -1;
        List<BiCan> lstBiCan;
        List<BiCan> lstBiCanDenHanTrongTuan;
        public frmReporttQuaHanTamGiam(int index)
        {
            InitializeComponent();
            pageIndex = index;
        }

        private void frmReporttQuaHanTamGiam_Load(object sender, EventArgs e)
        {
            reportViewer1.Reset();

            switch (pageIndex)
            {
                case 0:
                    lstBiCan = Query.GetAllBiCans_HasOutExpired_TamGiam();
                    break;
                case 1:
                    lstBiCan = Query.GetAllBiCans_HasOutExpired_TamGiam_DenHanTrongTuan();
                    break;
                case 2:
                    lstBiCan = Query.GetAllBiCans_HasOutExpired_TamGiam();
                    lstBiCanDenHanTrongTuan = Query.GetAllBiCans_HasOutExpired_TamGiam_DenHanTrongTuan();
                    lstBiCan.AddRange(lstBiCanDenHanTrongTuan);
                    break;
            }
            ConvertDate(lstBiCan);
        }
        private void ConvertDate(List<BiCan> lstBiCan)
        {
            foreach (BiCan biCan in lstBiCan)
            {
                if (biCan.DT_TuNgay != null)
                    biCan.DT_TuNgay = biCan.DT_TuNgay;
            }
            reportViewer1.LocalReport.DataSources.Clear(); //clear report
            reportViewer1.LocalReport.ReportEmbeddedResource = "QuanLyPhongGiam.rQuaHanTamGiam.rdlc"; // bind reportviewer with .rdlc

            Microsoft.Reporting.WinForms.ReportDataSource dataset = new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", lstBiCan); // set the datasource
            reportViewer1.LocalReport.DataSources.Add(dataset);
            dataset.Value = lstBiCan;
            this.reportViewer1.RefreshReport();
        }

        private void reportViewer1_Load(object sender, EventArgs e)
        {

        }
    }
}
